package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.ErmsFileDao;
import com.sugon.entity.ErmsFileEntity;
import com.sugon.service.ErmsFileService;
import com.sugon.utils.Constant;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ERMS资料附件关系表,分为设备、模具、工装等资料Service实现类
 *
 * @author YuXD
 * @date 2021-01-11 10:05:02
 */
@Service("ermsFileService")
public class ErmsFileServiceImpl implements ErmsFileService {
    @Autowired
    private ErmsFileDao ermsFileDao;

    @Override
    public ErmsFileEntity queryObject(String id) {
        return ermsFileDao.queryObject(id);
    }

    @Override
    public List<ErmsFileEntity> queryList(Map<String, Object> map) {
        return ermsFileDao.queryList(map);
    }

    @Override
    public List<ErmsFileEntity> queryList(String moduleId, Integer moduleType, String fileTypeId) {
        Map<String, Object> param = new HashMap<>(3);
        param.put("moduleId", moduleId);
        param.put("moduleType", moduleType);
        param.put("fileTypeId", fileTypeId);
        return ermsFileDao.queryList(param);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return ermsFileDao.queryTotal(map);
    }

    @Override
    public int save(ErmsFileEntity ermsFile) {
        ermsFile.setId(RandomUtil.randomString(32));
        ermsFile.setCreateUser(ShiroUtils.getUserId());
        ermsFile.setCreateDate(DateUtil.date());
        ermsFile.setDelFlag(Constant.IS_NOT_DEL_INT);
        ermsFile.setUpdateDate(ermsFile.getCreateDate());
        ermsFile.setUpdateUser(ShiroUtils.getUserId());
        return ermsFileDao.save(ermsFile);
    }

    @Override
    public int update(ErmsFileEntity ermsFile) {
        ermsFile.setUpdateDate(DateUtil.date());
        ermsFile.setUpdateUser(ShiroUtils.getUserId());
        return ermsFileDao.update(ermsFile);
    }

    @Override
    public int delete(String id) {
        return ermsFileDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return ermsFileDao.deleteBatch(ids);
    }
}
